 #!/usr/bin/python
 # -*- coding: utf-8 -*-

import iptables

p=iptables.getRules()
rules=iptables.parseConf(p)
f={'filter': ['FORWARD']} # i am adding to the FORWARD table
li=iptables.filterDict(rules, f)

orderno=0
rsltli=[]
for x in li["filter"]:
	orderno+=1
	keywords=("--sport", "--dport", "-p", "-j")
	if x == "-A FORWARD -o lo -j ACCEPT": continue
	else:
		srcli=x.split()
		
		li1=map(lambda x: srcli.index(x), keywords)
		indexli=map(lambda x: x+1, li1)
	
		try:
			srcip=srcli.index("-s")
			srcip+=1
		except:
			srcip=srcli.index("--src-range")
			srcip+=1
			
		
		try:
			dstip=srcli.index("-d")
			dstip+=1
		except:
			dstip=srcli.index("--dst-range")
			dstip+=1
			
		#print indexli
		rsltli.append("<"+str(orderno)+","+srcli[indexli[2]]+","+srcli[srcip]+","+srcli[indexli[0]]+","+srcli[dstip]+","+srcli[indexli[1]]+","+srcli[indexli[3]]+">" )	
			
				

print rsltli
	

